<html>
<head>
	<meta charset="UTF-8">
	<title>数据修改窗口</title>
	<link id="easyuiTheme" href="../../static/easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css"/>
	<link href="../../static/easyui/themes/frameless.css" rel="stylesheet" type="text/css"/>
	<script src="../../static/easyui/jquery.min.js" type="text/javascript"></script>
	<script src="../../static/easyui/jquery.cookie.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.easyui.util.js" type="text/javascript"></script>
	<script src="../../ffres/dict/all.js" type="text/javascript"></script>
	<link href="../../static/easyui/themes/icon.css" rel="stylesheet" type="text/css"/>
	<script src="../../static/easyui/ui-theme.js" type="text/javascript"></script>
	<script src="../../static/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../static/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.util.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.jquery.ajax.js" type="text/javascript"></script>
	<a href="" target="_blank" id="commonLink" name="commonLink"></a>
	<style type="text/css">
		/* div滚动条效果 */
		div.tabDiv{position:relative;text-align:center;padding-top:15px;height:325px;overflow: auto;}
		.tabDiv::-webkit-scrollbar {width: 5px;height:5px;}
		.tabDiv::-webkit-scrollbar-thumb {background-color: #CCC;} /* 滚动条的内层滑块颜色 */
		table,table tr th,table tr td{text-align:center;border: 1px solid #CCC;border-collapse:collapse;}
		table th{font-weight:normal;font-size:8px;}
		table td{font-size:8px;}
		/* 表格固定宽度、滚动展示 */
		.hd{min-width:60px;height:20px;overflow:hidden;white-space:nowrap;padding:1px;}
		.hd:hover{overflow:auto;}
		.hd::-webkit-scrollbar { width: 0px;height:0px;}
		/* 表格底部样式 */
		div.tBottom{position:relative;bottom:2px;height:25px;margin:auto;margin-top:2px;overflow: hidden;background-color: white}
		div.bottom{font-size: 8px;display: inline-block;margin:2px;}
		/* 页码效果 */
		.page{display:inline-block;bottom:0px;width:18px;height:18px;border:1px solid #CCC;line-height:18px;margin:0 auto;color:#999;text-decoration:none;}
		.page:hover{background-color:#CCC;}
		.page.on{background-color:#5173a0;color:white;}
		.hidden{display:none;}
	</style>
	<script type="text/javascript">
		var subsCode;
		var subsDsCode;

		$(function(){
			subsCode=window.parent.subsCode;
			subsDsCode=window.parent.subsDsCode;
		});

		function doExcetue(){
			var sql=$("#dd").val();
			var dboRemarks=$("#dboRemarks").textbox("getValue");
			var jsonData={subsCode:subsCode, subsDsCode:subsDsCode};
			if(sql==""){
				$.messager.alert('提示','sql语句不能为空！','info');
			}else if(dboRemarks==""){
				$.messager.alert('提示','请填写修改说明！','info');
			} else{
				$("#tb").empty();
				$("#tbTitle").empty();
				$("#tBottom").addClass("hidden");
				$.restfulPostForm('../../api/dbo/sql/run/'+dboRemarks+'/'+sql,jsonData,function(data){
					if(data.rows.length>0){
						createTable(data.rows);
					}
				},function(data){
					$("#tbTitle").append("<span href='#'>"+data.rows+"</span>");
				});
			}
		};

		//根据json数据生成表格
		function createTable(rows){
			var tableStr = '<thead><tr><th class="hd"></th>';
			var object = rows[0];
			for(var i in object)
				tableStr += '<th class="hd">' + i + '</th>';
			tableStr += '</tr></thead>';
			for(var i = 0; i < rows.length; i++){
				tableStr += '<tr><td>'+(i+1)+'</td>';
				for(var columnName in rows[i])
					if(rows[i][columnName]==null){
						tableStr += '<td></td>';
					}else{
						tableStr += '<td class="hd">' + rows[i][columnName] + '</td>';
					}
				tableStr += '</tr>';
			}
			$("#tbBottom").removeClass("hidden");
			$("#tb").append(tableStr);
			tablePaging(tb);
		}

		function tablePaging(table){
			var size=$("#selSize").children('option:selected').text();
			var rows= $("#"+table.id).find('tbody tr').length;
			var totalPage= Math.ceil(rows/size);//总页数
			$("#totalPage").text(totalPage);
			$("#pages").empty();
			$("#pages").append('<a href="#" style="width:27px;" class="page" id="firstPage" onclick="showPage(0,tb);window.event.returnValue=false;"><span>首页</span></a>');
			for(var page = 0; page<totalPage;page++){
				$("#pages").append('<a href="#" class="page" id="page-'+page+'" onclick="showPage('+page+',tb);window.event.returnValue=false;"><span>'+(page+1)+'</span></a>');
			}
			$("#pages").append('<a href="#" style="width:27px;" class="page" id="lastPage" onclick="showPage('+(totalPage-1)+',tb);window.event.returnValue=false;"><span>尾页</span></a>');
			showPage(0,table);
		}
		function showPage(page,table){
			var size=$("#selSize").children('option:selected').text();
			var totalPage=$("#totalPage").text();
			$("#db").remove();
			$("#"+table.id).find('tbody tr').hide().slice(page*size,(page+1)*size).show();
			$("#pages a").removeClass("on");
			$("#pages a").addClass("hidden");
			$("#firstPage").removeClass("hidden");
			$("#lastPage").removeClass("hidden");
			if(totalPage>10){
				if(page>=(totalPage-5)){
					for(var i=totalPage;i>totalPage-11;i--){
						$("#page-"+i).removeClass("hidden");
					}
				}else if(page<=4){
					for(var i=0;i<7;i++){
						$("#page-"+i).removeClass("hidden");
					}
					$($("#page-"+6)).after("<a href='#' id='db' class='page'><span>"+"..."+"</span></a>");
					for(var i=totalPage;i>totalPage-3;i--){
						$("#page-"+i).removeClass("hidden");
					}
				}else{
					for(var i=page-4;i<page+3;i++){
						$("#page-"+i).removeClass("hidden");
					}
					$($("#page-"+(page+2))).after("<a href='#' id='db' class='page'><span>"+"..."+"</span></a>");
					for(var i=totalPage;i>totalPage-3;i--){
						$("#page-"+i).removeClass("hidden");
					}
				}
			}else if(totalPage>1){
				$("#pages a").removeClass("hidden");
			}
			$("#page-"+page).addClass("on");
		}

		function doClearSQL(){
			$("#dd").val("");
		}
		function doClearResult(){
			$("#tbTitle").empty();
			$("#tb").empty();
			$("#pages").empty();
			$("#tbBottom").addClass("hidden");
		}
	</script>
</head>
<body class="easyui-layout">
<div id="updateWin">
<textarea id="dd" style="float:left;display:inline-block;margin-left:45px;margin-top:15px" rows="8" cols="130">
</textarea>
	<div style="margin-left:30px;display: inline-block;float:left;padding: 15px">
		<div  href="javascript:void(0)" class="easyui-linkbutton" onclick="doClearSQL()">清空SQL框</div >
		<div  href="javascript:void(0)" class="easyui-linkbutton" onclick="doClearResult()">清空结果框</div >
		<div  href="javascript:void(0)" class="easyui-linkbutton" onclick="doExcetue()">执行</div >
	</div>
	<div style="margin-left:30px;padding: 15px;display: inline-block;color: #444;font-size: 15px;">
		<span>数据修改说明：</span>
		<input class="easyui-textbox" type="text"
			   id="dboRemarks" name="dboRemarks" data-options="required:false"
			   style="width: 400px; height: 25px;"></input>
	</div>
	<div id="result" class="tabDiv" style="margin-left:45px;height:370px;width:1000px;border:1px solid #d7d3d3;">
		<div id="tbTitle" style="margin:auto;text-align: center;"></div>
		<div class="tabDiv">
			<table id="tb" style="margin:auto;">
			</table>
		</div>
		<div id="tbBottom" class="tBottom hidden">
			<div class="bottom">
				每页条数:<select id="selSize" onchange="tablePaging(tb)">
				<option>15</option>
				<option>30</option>
				<option>45</option>
				<option>60</option>
				<option>75</option>
			</select>
			</div>
			<div class="bottom" id="pages"></div>
			<div class="bottom">总页数:<a id="totalPage"></a></div>
		</div>
	</div>
</div>
</body>
</html>